package main.java.easy;

import main.java.structure.TreeNode;

/**
 * @Author: 郑国荣
 * @Date: 2023-07-30-16:05
 * @Description: 对称树
 */
public class SymmetricTree {
    public static boolean isSymmetric(TreeNode root) {

        return isSame(root.left,root.right);

    }
    public static boolean isSame(TreeNode p,TreeNode q){
        if (p==null && q==null) return true;
        if (p==null || q==null) return false;
        if (p.val == q.val){
            if (p.left!=null || q.right!=null) if (!isSame(p.left,q.right)) return false;
            if (p.right!=null || q.left!=null) if (!isSame(p.right,q.left)) return false;
        } else return false;
        return true;
    }

    public static void main(String[] args) {
        TreeNode root = new TreeNode(1,
                new TreeNode(2,new TreeNode(2),new TreeNode(1)),
                new TreeNode(2,new TreeNode(2),new TreeNode(2)));
        System.out.println(isSymmetric(root));
    }
}
